package com.burstly.lib.component.networkcomponent.burstly;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.GradientDrawable.Orientation;
import android.text.method.HideReturnsTransformationMethod;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import com.burstly.lib.component.IBurstlyAdaptor.BurstlyAdType;
import com.burstly.lib.component.IBurstlyAdaptorListener;
import com.burstly.lib.component.LayoutParametersResolver;
import com.burstly.lib.component.networkcomponent.ClickAwareWrapper;
import com.burstly.lib.component.networkcomponent.DelayedCallbackExecutor;
import com.burstly.lib.network.beans.DestinationType;
import com.burstly.lib.network.beans.ResponseBean.ResponseData;
import com.burstly.lib.network.request.DefaultRequestCallback;
import com.burstly.lib.network.request.ImageFetchTask;
import com.burstly.lib.service.SdCardWatchingService;
import com.burstly.lib.util.LoggerExt;
import com.burstly.lib.util.Utils;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
import java.security.SecureRandom;

final class BurstlyTextAdaptor extends AbstractBurstlyAdaptor
{
  private static final String APPSTORE_TYPE = "http://img.appads.com/icons/dest_appstore.png";
  private static final String AUDIO_TYPE = "http://img.appads.com/icons/dest_audio.png";
  private static final String CALL_TYPE = "http://img.appads.com/icons/dest_call.png";
  private static final String CUSTOM_TYPE = "http://img.appads.com/icons/dest_custom.png";
  private static final String INAPP_TYPE = "http://img.appads.com/icons/dest_inapp.png";
  private static final String ITUNES_TYPE = "http://img.appads.com/icons/dest_itunes.png";
  private static final String NETWORK_NAME = "burstlyText";
  private static final int PARSED_COLOR = 0;
  private static final String RSS_TYPE = "http://img.appads.com/icons/dest_rss.png";
  private static final SecureRandom SECURE_RANDOM = new SecureRandom();
  private static final String TWITTER_TYPE = "http://img.appads.com/icons/dest_twitter.png";
  private static final String VIDEO_TYPE = "http://img.appads.com/icons/dest_video.png";
  private static final String WEB_TYPE = "http://img.appads.com/icons/dest_website.png";
  String mAdText;
  private volatile int mComponentsToLoad;
  private ImageView mImageLeft;
  private ImageView mImageRight;
  private LinearLayout mLayout;
  volatile int mLoadedComponentsCount;
  private TextViewMultilineEllipse mText;
  private ImageFetchTask mTileTask;
  private ImageFetchTask mTypeTask;

  BurstlyTextAdaptor(Context paramContext, String paramString)
  {
    super(paramContext, paramString);
    this.mTag = (paramString + " BurstlyTextAdaptor");
    ImageCache.initCache(paramContext);
    SdCardWatchingService.startWatching(paramContext);
  }

  private void createLayout(Context paramContext)
  {
    this.mLayout = new LinearLayout(paramContext);
    this.mLayout.setClickable(true);
    this.mLayout.setGravity(17);
    GradientDrawable.Orientation localOrientation = GradientDrawable.Orientation.TOP_BOTTOM;
    int[] arrayOfInt = new int[2];
    arrayOfInt[0] = PARSED_COLOR;
    arrayOfInt[1] = -16777216;
    GradientDrawable localGradientDrawable = new GradientDrawable(localOrientation, arrayOfInt);
    Utils.setBackgroundDrawable(this.mLayout, localGradientDrawable);
    this.mLayout.setFocusable(true);
    getResponseData().setAdType(null);
    this.mLayout.setLayoutParams(getLayoutParamsResolver().resolveParameters());
  }

  private void createLeftImage(Context paramContext)
  {
    this.mImageLeft = new ImageView(paramContext);
    this.mImageLeft.setId(SECURE_RANDOM.nextInt());
    LinearLayout.LayoutParams localLayoutParams = new LinearLayout.LayoutParams(-2, Utils.getFillparentValue());
    localLayoutParams.leftMargin = 5;
    localLayoutParams.topMargin = 5;
    localLayoutParams.bottomMargin = 5;
    localLayoutParams.gravity = 3;
    this.mLayout.addView(this.mImageLeft, localLayoutParams);
  }

  private void createRightImage(Context paramContext)
  {
    this.mImageRight = new ImageView(paramContext);
    this.mImageRight.setId(SECURE_RANDOM.nextInt());
    LinearLayout.LayoutParams localLayoutParams = new LinearLayout.LayoutParams(-2, Utils.getFillparentValue());
    localLayoutParams.rightMargin = 5;
    localLayoutParams.topMargin = 5;
    localLayoutParams.bottomMargin = 5;
    localLayoutParams.gravity = 5;
    this.mLayout.addView(this.mImageRight, localLayoutParams);
  }

  private void createTextField(Context paramContext)
  {
    this.mText = new TextViewMultilineEllipse(paramContext);
    this.mText.setId(SECURE_RANDOM.nextInt());
    int i = Utils.getFillparentValue();
    LinearLayout.LayoutParams localLayoutParams = new LinearLayout.LayoutParams(i, i, 1.0F);
    localLayoutParams.leftMargin = 5;
    localLayoutParams.rightMargin = 5;
    localLayoutParams.topMargin = 5;
    localLayoutParams.gravity = 17;
    this.mLayout.addView(this.mText, localLayoutParams);
  }

  private void getTileIcon(String paramString)
  {
    if (paramString != null)
    {
      this.mComponentsToLoad = (1 + this.mComponentsToLoad);
      LOG.logInfo(this.mTag, "Server passed a burstly tile image...", new Object[0]);
      createLeftImage(getContext());
      this.mTileTask = new ImageFetchTask(paramString, new ImageCallback(this, this.mImageLeft));
      this.mTileTask.setCache(ImageCache.getInstance());
      this.mTileTask.setScale(Utils.getScale(getContext()));
      this.mTileTask.execute(new Void[0]);
    }
  }

  private void getTypeIcon(String paramString)
  {
    if (paramString != null)
    {
      this.mComponentsToLoad = (1 + this.mComponentsToLoad);
      LOG.logInfo(this.mTag, "Server passed a burstly type image...", new Object[0]);
      createRightImage(getContext());
      this.mTypeTask = new ImageFetchTask(paramString, new ImageCallback(this, this.mImageRight));
      this.mTypeTask.setCache(ImageCache.getInstance());
      this.mTypeTask.setScale(Utils.getScale(getContext()));
      this.mTypeTask.execute(new Void[0]);
    }
  }

  private void loadType()
  {
    Integer localInteger = getResponseData().getDestType();
    if (localInteger.equals(DestinationType.DestinationType_rss.getValue()))
      getTypeIcon("http://img.appads.com/icons/dest_rss.png");
    do
    {
      return;
      if (localInteger.equals(DestinationType.DestinationType_twitter.getValue()))
      {
        getTypeIcon("http://img.appads.com/icons/dest_twitter.png");
        return;
      }
      if (localInteger.equals(DestinationType.DestinationType_webSite.getValue()))
      {
        getTypeIcon("http://img.appads.com/icons/dest_website.png");
        return;
      }
      if (localInteger.equals(DestinationType.DestinationType_audio.getValue()))
      {
        getTypeIcon("http://img.appads.com/icons/dest_audio.png");
        return;
      }
      if (localInteger.equals(DestinationType.DestinationType_video.getValue()))
      {
        getTypeIcon("http://img.appads.com/icons/dest_video.png");
        return;
      }
      if (localInteger.equals(DestinationType.DestinationType_appStore.getValue()))
      {
        getTypeIcon("http://img.appads.com/icons/dest_appstore.png");
        return;
      }
      if (localInteger.equals(DestinationType.DestinationType_call.getValue()))
      {
        getTypeIcon("http://img.appads.com/icons/dest_call.png");
        return;
      }
      if (localInteger.equals(DestinationType.DestinationType_iTunes.getValue()))
      {
        getTypeIcon("http://img.appads.com/icons/dest_itunes.png");
        return;
      }
      if (localInteger.equals(DestinationType.DestinationType_custom.getValue()))
      {
        getTypeIcon("http://img.appads.com/icons/dest_custom.png");
        return;
      }
    }
    while (!localInteger.equals(DestinationType.DestinationType_inAppPurchase.getValue()));
    getTypeIcon("http://img.appads.com/icons/dest_inapp.png");
  }

  private void setInitValues()
  {
    this.mLoadedComponentsCount = 1;
    this.mComponentsToLoad = 0;
  }

  private ViewGroup wrap(View paramView)
  {
    ClickAwareWrapper localClickAwareWrapper = new ClickAwareWrapper(getContext(), getAdaptorListener(), getViewId(), "burstlyText");
    localClickAwareWrapper.addView(paramView);
    return localClickAwareWrapper;
  }

  protected View doGetNewAd()
  {
    setInitValues();
    this.mComponentsToLoad = (1 + this.mComponentsToLoad);
    Context localContext = getContext();
    createLayout(localContext);
    getTileIcon(getResponseData().getImageUrl());
    createTextField(localContext);
    String str1 = getResponseData().getAdText();
    if (str1 != null);
    for (String str2 = str1.replace("\r", ""); ; str2 = "")
    {
      this.mAdText = str2;
      setText(this.mAdText);
      loadType();
      if (this.mComponentsToLoad == 1)
        new DelayedCallbackExecutor(100L).execute(new Runnable()
        {
          public void run()
          {
            BurstlyTextAdaptor.this.notifyIfLoaded();
          }
        });
      return wrap(this.mLayout);
    }
  }

  void failed()
  {
    stop();
    getAdaptorListener().failedToLoad("burstlyText", false, "");
  }

  public IBurstlyAdaptor.BurstlyAdType getAdType()
  {
    return IBurstlyAdaptor.BurstlyAdType.BANNER_AD_TYPE;
  }

  public String getNetworkName()
  {
    return "burstlyText";
  }

  void notifyIfLoaded()
  {
    if (this.mLoadedComponentsCount == this.mComponentsToLoad)
    {
      LOG.logInfo(this.mTag, "Tracking show...", new Object[0]);
      getAdaptorListener().didLoad("burstlyText", false);
    }
  }

  public View precacheAd()
  {
    return getNewAd();
  }

  public void setText(String paramString)
  {
    String str = HideReturnsTransformationMethod.getInstance().getTransformation(paramString, this.mLayout).toString();
    this.mText.setText(str);
  }

  public void stop()
  {
    super.stop();
    Utils.cancelTask(this.mTileTask);
    Utils.cancelTask(this.mTypeTask);
    this.mTileTask = null;
    this.mTypeTask = null;
  }

  public boolean supports(String paramString)
  {
    return true;
  }

  private static class ImageCallback extends DefaultRequestCallback<Bitmap>
  {
    private final Reference<BurstlyTextAdaptor> mAdaptor;
    private final Reference<ImageView> mImageView;

    ImageCallback(BurstlyTextAdaptor paramBurstlyTextAdaptor, ImageView paramImageView)
    {
      this.mAdaptor = new WeakReference(paramBurstlyTextAdaptor);
      this.mImageView = new WeakReference(paramImageView);
    }

    public void onFailUi(Bitmap paramBitmap)
    {
      BurstlyTextAdaptor localBurstlyTextAdaptor = (BurstlyTextAdaptor)this.mAdaptor.get();
      if ((localBurstlyTextAdaptor != null) && (!localBurstlyTextAdaptor.isStopped()))
      {
        BurstlyTextAdaptor.LOG.logError(localBurstlyTextAdaptor.mTag, "Failed to load type image from url", new Object[0]);
        localBurstlyTextAdaptor.failed();
      }
    }

    public void onSuccessUi(Bitmap paramBitmap)
    {
      BurstlyTextAdaptor localBurstlyTextAdaptor = (BurstlyTextAdaptor)this.mAdaptor.get();
      ImageView localImageView = (ImageView)this.mImageView.get();
      if ((localBurstlyTextAdaptor != null) && (localImageView != null) && (!localBurstlyTextAdaptor.isStopped()))
      {
        localImageView.setAdjustViewBounds(true);
        localImageView.setImageBitmap(paramBitmap);
        BurstlyTextAdaptor.LOG.logInfo(localBurstlyTextAdaptor.mTag, "Type image fetched by url came from burstly.", new Object[0]);
        localBurstlyTextAdaptor.mLoadedComponentsCount = (1 + localBurstlyTextAdaptor.mLoadedComponentsCount);
        localBurstlyTextAdaptor.notifyIfLoaded();
      }
    }
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.burstly.lib.component.networkcomponent.burstly.BurstlyTextAdaptor
 * JD-Core Version:    0.6.2
 */